const http = require("http");
const fs = require("fs");
const path = require("path");

var filePath = path.join(__dirname, "/data.json");

http.createServer((req, res) => {
    var str = "";
    req.on("data", (chunk) => {
        str += chunk;
    })
    req.on("end", () => {
        var readResult = fs.readFileSync(filePath);
        var readStr = readResult.toString("utf-8");
        readStr = JSON.parse(readStr);
        var keys = Object.values(readStr);
        var obj = JSON.parse(str);

        keys[0].forEach((key, index) => {
            if(keys[0][index].userName == obj.userName && keys[0][index].pwd == obj.pwd){
                console.log("成功登录");
            }
            else{
                console.log("用户名、密码错误");
            }
        })
    })
}).listen(8081);

